//////////////////////////////////////////////////////////////////////////
//
//  Name:   FPSCalculator.h
//
//  Desc:   Class that computes frames per second.
//
//  Author: Nicolas Bertoa - nicobertoa@gmail.com
//
//////////////////////////////////////////////////////////////////////////

#ifndef UTILS_FPS_H
#define UTILS_FPS_H

#include <cstdint>

#include <SFML/System/Clock.hpp>

namespace Utils	
{
	class FPSCalculator
	{
	public:
		FPSCalculator()
		: mElapsedFrames(0)
		, mFramesPerSecond(0)
		{
			mClock.Reset();
		}

	public:
		void Update() 
		{
			// If one second passed, then we update 
			// the frames in the last second.
			if(sOneSecond <= mClock.GetElapsedTime())
			{
				// Update fps
				mFramesPerSecond = mElapsedFrames;

				// Reset the current frame and clock.
				mElapsedFrames = 0;
				mClock.Reset();
			}

			else
				mElapsedFrames;
		}

		uint16_t GetFPS() const { return mFps; }

	private:
		static const float sOneSecond; // One second in miliseconds.
		
		sf::Clock mClock; // The clock where we can get the milliseconds elapsed.

		uint16_t mElapsedFrames // Current frame.

		uint16_t mFramesPerSecond; // Current fps
	};
}

#endif // UTILS_FPS_H
